package com.deanlib.cabinet.data.model;

import com.deanlib.cabinet.data.AppDatabase;
import com.deanlib.cabinet.data.db.ResourceCacheDao;
import com.deanlib.plantern.utils.FileUtils;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;

import java.io.File;
import java.sql.Timestamp;
import org.greenrobot.greendao.annotation.Generated;

/**
 * 资源缓存表
 * @Created by Dean
 * @Date 2023/6/11
 */
@Entity
public class ResourceCache {

    @Id
    public String md5;
    public String path;
    public String netPath;
    public String thumbnailPath;
    public Long createTime;//写数据库时间
    @Generated(hash = 1283511369)
    public ResourceCache(String md5, String path, String netPath,
            String thumbnailPath, Long createTime) {
        this.md5 = md5;
        this.path = path;
        this.netPath = netPath;
        this.thumbnailPath = thumbnailPath;
        this.createTime = createTime;
    }
    @Generated(hash = 1455886856)
    public ResourceCache() {
    }
    public String getMd5() {
        return this.md5;
    }
    public void setMd5(String md5) {
        this.md5 = md5;
    }
    public String getPath() {
        return this.path;
    }
    public void setPath(String path) {
        this.path = path;
    }
    public String getNetPath() {
        return this.netPath;
    }
    public void setNetPath(String netPath) {
        this.netPath = netPath;
    }
    public String getThumbnailPath() {
        return this.thumbnailPath;
    }
    public void setThumbnailPath(String thumbnailPath) {
        this.thumbnailPath = thumbnailPath;
    }
    public Long getCreateTime() {
        return this.createTime;
    }
    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public static String getCacheDir(){
        return FileUtils.getDiskCachePath() + File.separator + "resource_cache";
    }

    public static String createCachePath(String md5){
        return getCacheDir() + File.separator + md5;
    }

    public static String createCacheThumbnailPath(String md5){
        return getCacheDir() + File.separator + md5+"_thumbnail";
    }

    public static ResourceCache getCache(String md5){
        return AppDatabase.getDaoSession().getResourceCacheDao().load(md5);
    }
}
